/**
 * Copyright (c) 2010 CWI Amsterdam and others. All rights reserved.
 * This program and the accompanying materials are made available
 * under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     CWI Amsterdam - initial API and implementation
 *
 * $Id$
 */
package nl.cwi.arne.mcrl2;

import nl.cwi.arne.mcrl2.factory.MCRL2Package;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;

/**
 * @see nl.cwi.arne.mcrl2.factory.MCRL2Package#getBasicTerm()
 * @model kind="class"
 * @generated
 */
public class BasicTerm extends Nameable implements Term {

	/**
	 * Constructor.
	 * @generated NOT
	 */
	public BasicTerm(String value, Type type) {
		setType(type);
		setName(value);
	}

	/**
	 * Constructor.
	 * @generated NOT
	 */
	public BasicTerm(boolean value) {
		this(String.valueOf(value), PrimitiveType.BOOL);
	}
	
	/**
	 * Constructor.
	 * @generated NOT
	 */
	public BasicTerm(Constraint constraint) {
		this(constraint.toString(), PrimitiveType.BOOL);
	}

	/**
	 * Constructor.
	 * @generated NOT
	 */
	public BasicTerm(int value) {
		this(String.valueOf(value), PrimitiveType.INT);
	}

	/**
	 * Constructor.
	 * @generated NOT
	 */
	public BasicTerm(String value, Sort type) {
		this(value, new SortType(type));
	}

	/**
	 * Constructor.
	 * @generated NOT
	 */
	public BasicTerm(Element element) {
		this(element.getName(), element.getStructure());
	}

	/**
	 * Constructor.
	 * @generated NOT
	 */
	public BasicTerm(Atom atom) {
		setType(atom.getType());
		setName(atom.getName());
	}

	/**
	 * @generated NOT
	 */
	@Override
	public String toString() {
		return getName();
	}
	
	/* ---------------------------------------------------------------- *
	 * GENERATED CODE.                                                  *
	 * Do not edit below this line. If you need to edit, move it above  *
	 * this line and change the '@generated'-tag to '@generated NOT'.   *
	 * ---------------------------------------------------------------- */
	
	/**
	 * The cached value of the '{@link #getType() <em>Type</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getType()
	 * @generated
	 * @ordered
	 */
	protected Type type;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public BasicTerm() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return MCRL2Package.Literals.BASIC_TERM;
	}

	/**
	 * Returns the value of the '<em><b>Type</b></em>' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @return the value of the '<em>Type</em>' reference.
	 * @see #setType(Type)
	 * @see nl.cwi.arne.mcrl2.factory.MCRL2Package#getBasicTerm_Type()
	 * @model
	 * @generated
	 */
	public Type getType() {
		if (type != null && type.eIsProxy()) {
			InternalEObject oldType = (InternalEObject)type;
			type = (Type)eResolveProxy(oldType);
			if (type != oldType) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, MCRL2Package.BASIC_TERM__TYPE, oldType, type));
			}
		}
		return type;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Type basicGetType() {
		return type;
	}

	/**
	 * Sets the value of the '{@link nl.cwi.arne.mcrl2.BasicTerm#getType <em>Type</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @param value the new value of the '<em>Type</em>' reference.
	 * @see #getType()
	 * @generated
	 */
	public void setType(Type newType) {
		Type oldType = type;
		type = newType;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, MCRL2Package.BASIC_TERM__TYPE, oldType, type));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case MCRL2Package.BASIC_TERM__TYPE:
				if (resolve) return getType();
				return basicGetType();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case MCRL2Package.BASIC_TERM__TYPE:
				setType((Type)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case MCRL2Package.BASIC_TERM__TYPE:
				setType((Type)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case MCRL2Package.BASIC_TERM__TYPE:
				return type != null;
		}
		return super.eIsSet(featureID);
	}

} // BasicTerm
